/** 表单信息 */
export const formMixin = {
	data() {
		return {
			classification: {
				"spec_item_name": '',
				"shop_price": '',
			},
			buyNum: 1, // 购买数量
			popupShow1653961165769: false, // 是否显示sku
		}
	},
	onLoad() { uni.removeStorageSync("CONFIRM_GOOD_INFO"); },
	methods: {
		/** 去添加地址 */
		toAddAddr() { uni.navigateTo({ url: "/pages/yhq/editAddress/editAddress" }) },
		/** 用户信息认证 */
		uiAuthen() {
			// if (!uni.getStorageSync('USER_TOKEN')) {
			// 	uni.navigateTo({ url: "/pages/tabBar/passwordLogin/passwordLogin" })
			// 	return false;
			// } else if (!this.classification.sku_id && this.goodData.is_open_sku == 1) {
			// 	this.openSpec();
			// 	return false;
			// } else if (!this.addressInfo.address_id) {
			// 	this.$msg("请选择收货地址")
			// 	this.popupShow1653961165769 = false;
			// 	this.popupShow1698314536945 = true;
			// 	return false;
			// }
			if (!this.classification.sku_id && this.goodData.is_open_sku == 1) {
				this.openSpec();
				return false;
			} else if (!this.addressInfo.address_id) {
				this.$msg("请选择收货地址")
				this.popupShow1653961165769 = false;
				this.popupShow1698314536945 = true;
				return false;
			}
			return true;
		},
		/** 加入购物车 */
		async addCard() {
			if (!this.uiAuthen()) return;
			try {
				const res = await this.$post('6551c656acea0', {
					goods_id: this.id,
					sku_id: this.classification.sku_id,
					num: this.buyNum,
				});
				this.$msg(res.msg || "成功");
				this.popupShow1653961165769 = false;
			} catch (e) { this.$msg(e?.msg || "失败") }
		},
		/** 去购买 */
		async toBuyGood() {
			if (!this.uiAuthen()) return;
			this.popupShow1653961165769 = false;
			var goods_info = [{ goods_id: this.id, num: this.buyNum, sku_id: this.classification.sku_id }];
			var address_id = this.addressInfo.address_id;
			uni.setStorageSync("CONFIRM_GOOD_INFO", { goods_info, address_id });
			uni.navigateTo({ url: "/pages/grzx/cartBilling/cartBilling" })
		},
		/** 去支付定金【废弃】 */
		async toBuyDingjin() {
			if (!this.uiAuthen()) return;
			this.popupShow1653961165769 = false;
			var goods_info = [{ goods_id: this.id, num: this.buyNum, sku_id: this.classification.sku_id }];
			var address_id = this.addressInfo.address_id;
			uni.setStorageSync("CONFIRM_GOOD_INFO", { goods_info, address_id });
			uni.navigateTo({ url: "/pages/grzx/cartBilling/cartBilling" })
		},
		// 选择规格
		selectSpec(k, key) {
			this.spec_list[k].child.forEach((v, k) => {
				v.isSelect = false;
			})
			this.spec_list[k].child[key].isSelect = true;
			this.$forceUpdate();
			let specs = '';
			this.spec_list.forEach((v, k) => {
				if (v.child.length > 0) {
					v.child.forEach((v1, k1) => {
						if (v1.isSelect) {
							specs += v.child[k1].id + '_';
						}
					})
				}
			})
			specs = specs.substring(0, specs.length - 1);
			for (var i in this.sku_list) {
				if (specs == this.sku_list[i].spec_item_id) {
					this.classification = this.sku_list[i];
					console.log(this.classification);
				}
			}
		},
		// 打开规格
		openSpec() {
			// this.sku_open_type = sku_open_type;
			// if (this.classification.shop_price) return;
			if (this.classification.sku_id) this.popupShow1653961165769 = true;
			else if (this.spec_list.length > 0) {
				this.popupShow1653961165769 = true;
				let specs = '';
				this.spec_list.forEach((v, k) => {
					if (v.child.length > 0) {
						v.child.forEach((v1, k1) => {
							if (k1 == 0) {
								v1.isSelect = true;
								specs += v1.id + '_';
							} else {
								v1.isSelect = false;
							}
						})
					}
				})
				specs = specs.substring(0, specs.length - 1);
				// console.log(specs);
				for (var i in this.sku_list) {
					if (specs == this.sku_list[i].spec_item_id) {
						this.classification = this.sku_list[i];
						console.log(this.classification);
					}
				}
			} else {
				this.$message.info('暂无规格可以选择');
			}
		},
	}
}